﻿using System;

namespace Core
{
    public class FrameItem : Core.Component
    {
        public Action<int> Func;
        public int Interval;
        //public bool Immediate;

        private int elapsedFrame;

        public void Start()
        {
            //if (Immediate == true)
            //{
            //    Func(0);
            //}

            elapsedFrame = Interval;
        }

        public void Update()
        {
            elapsedFrame -= 1;

            if (elapsedFrame <= 0)
            {
                elapsedFrame += Interval;
                try
                {
                    Func(Interval);
                }
                catch (Exception e)
                {
                    log.err(e);
                }
            }
        }

        public override void Dispose()
        {
            if (IsDisposed) return;
            base.Dispose();


        }
    }
}
